package com.singzi.leetcode.jianzhiOffer;

public class T0042 {
}
class Solution0042 {
    public int maxSubArray(int[] nums) {

        int sum = 0;
        int temp = 0;
        for(Integer num:nums){

            if(num > 0){
                sum +=num;
                if(sum > temp){
                    temp = sum;
                }
            }
            else {
                sum = Math.max(sum + num, 0);
            }

        }


        return temp;

    }
}